package com.qf.business.user.controller;




import com.qf.business.user.service.UserService;
import com.qf.data.base.r.R;
import com.qf.data.base.r.Rs;
import com.qf.data.base.utils.QfBeanUtils;
import com.qf.data.user.entity.User;
import com.qf.data.user.vo.input.WXUserInput;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * (User)表控制层
 *
 * @author makejava
 * @since 2022-07-05 09:52:54
 */
@RestController
@RequestMapping("/user/wx")
public class UserController  {

    @Autowired
    private UserService userService;

    @RequestMapping("/query")
    public R<User> wxUserQuery(@RequestBody @Valid WXUserInput wxUserInput){
        //将input对象转换成 entity 对象
        User user = QfBeanUtils.beanCopy(wxUserInput,User.class);
        //查询数据库的用户信息
        User dataUser = userService.queryByOpenId(user.getOpenId());
        if (dataUser == null) {
            //数据库没有用户信息，保存当前的所有信息
            userService.save(user);
            return Rs.create(user);
        }
        return Rs.create(dataUser);
    }
  
}

